{
    //静态代理
    interface Subject {
        doOperation(): void
    }

    class SpecificSubject implements Subject {
        doOperation(): void {
            console.log("SpecificSubject is working");
        }
    }

    class Proxy implements Subject {
        private target: Subject

        constructor(specificSubject: SpecificSubject) {
            this.target = specificSubject
        }

        doOperation(): void {
            console.log(this.target);
            this.target.doOperation()
        }
    }

    const ProxyTest = (): void => {
        const specificSubject: SpecificSubject = new SpecificSubject()
        const myProxy: Subject = new Proxy(specificSubject)
        myProxy.doOperation()
    }

    ProxyTest()
}
console.log("---------------------- :>> ")
{
    //动态代理
    interface Subject {
        doOperation(): void
    }

    class SpecificSubject implements Subject {
        constructor() { }
        doOperation(): void {
            console.log("SpecificSubject is working")
        }
    }

    class ProxyFactory {
        private target: any
        constructor(target: any) {
            this.target = target
        }

        public createProxyInstance(): any {
            return new Proxy(this.target, {
                get: (target, propKey) => {
                    //一些具体拦截逻辑
                    return target[propKey]
                }
            })
        }
    }

    const ProxyTest = (): void => {
        const target: Subject = new SpecificSubject()
        const proxyInstance: Subject = <Subject>new ProxyFactory(target).createProxyInstance()
        proxyInstance.doOperation()
    }

    ProxyTest()
}


